/*
Copyright 2005-2014 CP Fricano - All Rights Reserved

This software and source code is licensed under the Apache
License, Version 2.0. You may not use this software or source
code except in compliance with the License.  You may obtain a
copy of the License at: http://www.apache.org/licenses/LICENSE-2.0.
Use and distributed under this License is on an "as is" basis,
without expressed or implied warranties or conditions of any kind.
See the License for the specific language governing permissions and
limitations.
 */

package com.fricano.java42.swing.dings.tester;

import java.awt.Container;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.fricano.java42.sequencer.J42Helper;
import com.fricano.java42.sequencer.J42Listener;
import com.fricano.java42.sequencer.J42Sequencer;
import com.fricano.java42.swing.dings.J42SwingDingController_Slider.Alignment;
import com.fricano.java42.swing.dings.J42SwingDingManager_Slider;
import com.fricano.java42.swing.dings.J42SwingDing_Factory;

final public class J42SwingDing_SlidableTest_02 {

    private static Window             jParentTEST;
    private static JButton            jParentB       = new JButton("BBBB");
    private static JPanel             jChildTEST;

    static J42SwingDing_Factory       dingController = null;
    static J42SwingDingManager_Slider slideManager1  = null;
    static J42SwingDingManager_Slider slideManager2  = null;
    static J42SwingDingManager_Slider slideManager3  = null;

    static public void main(final String[] args) throws Exception {

        new J42Sequencer<JFrame>(J42Sequencer.LookAndFeel.SYSTEM) {

            @Override
            public void doSequence0_CreateComponents(final JFrame window, final Container contentPane, final J42Helper<JFrame> helper) {
                dingController = new J42SwingDing_Factory(window);

                slideManager1 = dingController.create_SlideManager();
                slideManager2 = dingController.create_SlideManager();
                slideManager3 = dingController.create_SlideManager();

            }

            @Override
            public void doSequence1_AddComponents(final JFrame jFrame, final Container contentPane, final J42Helper<JFrame> helper) {

                {
                    final JButton b = new JButton("Slide Right");
                    // b.addActionListener(e -> slideManager1.slideToggle(true));
                    b.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(final ActionEvent e) {
                            slideManager1.slideToggle(true);
                        }
                    });

                    contentPane.add(b);
                }

                {
                    final JButton b = new JButton("Slide Bottom");
                    // b.addActionListener(e -> slideManager2.slideToggle(true));
                    b.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(final ActionEvent e) {
                            slideManager2.slideToggle(true);
                        }
                    });

                    contentPane.add(b);
                }

                {
                    helper.addJButton(contentPane, "INTERIOR_TOP", new J42Listener<JButton, ActionEvent>() {
                        @Override
                        public void doWorkOutsideEDT(final JButton t, final ActionEvent eventObject) throws Exception {
                            if (slideManager3.isClosed()) {
                                slideManager3.slideOpen(true);
                            }
                            else {
                                slideManager3.slideClosed(true);
                            }
                        }

                        @Override
                        public void doWorkInsideEDT(final JButton t, final ActionEvent eventObject) throws Exception {
                        }
                    });
                }

            }

            @Override
            public void doSequence2_LocateSizePackShow(final JFrame window, final Container contentPane, final J42Helper<JFrame> helper) {

                window.setLocationRelativeTo(null);
                window.setVisible(true);
            }

            @Override
            public void doSequence3_StartApplication(final JFrame window, final Container contentPane, final J42Helper<JFrame> helper) {

                final JButton jButton1 = new JButton("JButton_01");
                jButton1.setSize(100, 50);
                slideManager1.attachSlider(Alignment.INTERIOR_RIGHT, jButton1, 42, 500, 0, 0);

                final JButton jButton2 = new JButton("JButton_02");
                jButton2.setSize(100, 50);
                slideManager2.attachSlider(Alignment.INTERIOR_BOTTOM, jButton2, 42, 500, 0, 0);

                final JButton jButton3 = new JButton("JButton_03");
                jButton3.setSize(100, 50);
                slideManager3.attachSlider(Alignment.INTERIOR_TOP, jButton3, 42, 500, 0, 0);

            }

            @Override
            public void doSequence9_StopApplication(final JFrame window, final Container contentPane, final J42Helper<JFrame> helper) {

            }

        };

    }

}
